package  
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	/**
	 * ...
	 * @author patsup
	 * 
	 * 		Generalized Button for use in menu's (although StartMenu was born too early to take advantage of this).
	 * 	Uses ImageData class to pass in image data used to draw the button.
	 * 	Calls inputFunc() on a mouseclick input event.
	 * 
	 */
	public class MenuButton extends Button 
	{
		private var inputFunc:Function;							//function to call on mouseclick
		private var imgData:ImageData;							//data for initializing image
		private var mc:MovieClip;								//the "real" image data...
		
		private var btnLabel:TextField;							//button label
		
		public function MenuButton(imgData:ImageData, inputFunc:Function, mc:MovieClip = null) 
		{
			name = imgData.GetText() + " Button";
			btnLabel = new TextField();
			
			this.inputFunc = inputFunc;
			this.imgData = imgData;
			this.mc = mc;
			
			InitInput();
			InitImage();
			
			super(imgData.GetX(), imgData.GetY());
		}
		
		//SetButtonLabel
		public function SetButtonLabel(label:String):void
		{
			btnLabel.text = label;
			btnLabel.width = btnLabel.textWidth*1.2;			//adjust the textfield's dimensions
			btnLabel.height = btnLabel.textHeight*1.5;
			btnLabel.x = 0.5 * imgData.GetWidth() - 0.5 * btnLabel.width;
			btnLabel.y = 0.5 * imgData.GetHeight() - 0.5 * btnLabel.height;
		}
		
		//InitImage()
		//Initializes the image of the Menu Button
		protected override function InitImage():void
		{
			graphics.beginFill(imgData.GetColor(), imgData.GetAlpha());
			if(imgData.GetType() == "Ellipse") {
				graphics.drawEllipse(0, 0, imgData.GetWidth(), imgData.GetHeight());
			} else {
				graphics.drawRect(0, 0, imgData.GetWidth(), imgData.GetHeight());
			}
			graphics.endFill();
			
			if (mc != null) {
				addChild(mc);
			}
			
			
			btnLabel.text = imgData.GetText();
			btnLabel.width = btnLabel.textWidth*1.2;			//adjust the textfield's dimensions
			btnLabel.height = btnLabel.textHeight*1.5;
			btnLabel.x = 0.5 * imgData.GetWidth() - 0.5 * btnLabel.width;
			btnLabel.y = 0.5 * imgData.GetHeight() - 0.5 * btnLabel.height;
			addChild(btnLabel);									//now add this txt label to the display list
			
			super.InitImage();
		}
		
		//InputMouseClick()
		//Takes action for Menu Button upon hearing the mouseclick event
		protected override function InputMouseClick(e:MouseEvent):void
		{
			
			inputFunc();
			super.InputMouseClick(e);
		}
		
		//ChangeIMCFunc()
		//Change the InputMouseClick Function
		public function ChangeIMCFunc(inputFunc:Function):void
		{
			this.inputFunc = inputFunc;
		}
		
	}

}